<?php
namespace Demo\App\Controller;

use Swork\Bean\Annotation\Controller;
use Swork\Bean\Annotation\Reference;
use Swork\Bean\BeanCollector;
use Swork\Server\Http\Argument;
use Swork\Server\Tasker;

/**
 * Class IndexController
 * @Controller("/task")
 */
class TaskController extends BeanCollector
{
    /**
     * @Reference()
     * @var \Demo\App\Service\TestInterface
     */
    private $testInterface;

    /**
     * 测试
     * @param Argument $args
     * @return mixed
     * @throws
     */
    public function index(Argument $args)
    {
        Tasker::deliver(TaskController::class, 'cal', [12, 5]);

        try
        {
            $result = $this->testInterface->mysql();
            return $result;
        }
        catch (\Throwable $e)
        {
            var_dump($e->getMessage());
        }

        return ['ok'];
    }

    public function cal(int $a, int $b)
    {
        echo "a: $a  -- b：$b" . PHP_EOL;

        $count = $this->testInterface->info(100, 2001);
        var_dump('count >>> ' . $count);

        Tasker::deliver(TaskController::class, 'child', [[1, 2, 3]]);
    }

    public function child(array $arg)
    {
        var_dump($arg);
    }
}
